package com.lelefly.serlvet;

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;

import javax.servlet.http.HttpServlet;

import com.lelefly.db.dbmanager.HibernateSessionFactory;




public class TomcatStartServlet extends HttpServlet {
	
	//时间间隔一天
	private static final long PERIOD_DAY = 24*60*60*1000;
	
	@Override
	public void init()
	{
		
		//定时删除过期文件
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.HOUR_OF_DAY, 2); 	//凌晨2点
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		Date date = calendar.getTime();
		if(date.before(new Date()))
		{
			date = addDay(date,1);
		}
		Timer timer = new Timer();
		ClearDirTask task = new ClearDirTask();
		timer.schedule(task, date, PERIOD_DAY);
	}
	
	private Date addDay(Date date, int i) {
		Calendar start = Calendar.getInstance();
		start.setTime(date);
		start.add(Calendar.DAY_OF_MONTH, i);
		return start.getTime();
	}
	
}
